<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>跟进中的统计报表</title>
    <c:import url="../../header.jsp"/>
</head>
<body>
<div class="content-warp">
    <%--页面切换栏--%>
    <div class="screen-tab-warp">
        <ul class="screen-tab">
            <li class="active tab-switch" data-target="1"><a href="javascript:void(0)">抵押贷款</a></li>
            <li class="tab-switch" data-target="2"><a href="javascript:void(0)">信用贷款</a></li>
            <li class="tab-switch" data-target="3"><a href="javascript:void(0)">资金业务</a></li>
        </ul>
    </div>
    <div id="screeningArea"></div>
</div>

<c:import url="../../footer.jsp"/>
<script>
    var tables;
    var completeOrder = {
        "list": sysInfo.basePath + "/report/follow_up_report_data.do",//分页数据
        "mortgage_loan": sysInfo.basePath + "/report/mortgage_loan.html",
        "credit_loan": sysInfo.basePath + "/report/credit_loan.html",
        "capital_business": sysInfo.basePath + "/report/capital_business.html",
        "timeName" : "退单时间",
        "reasonName" : "退单原因",
        "completeTd" : "RZSCORDER_STATUS06",//已退单
        "completeFd" : "RZSCORDER_STATUS08"//已废单
    };

    dggui.use(['table', 'select2','distpicker','dggdate','droptree'], function () {
        var table = dggui.table;
        var select2 = dggui.select2;
        var distpicker=dggui.distpicker;
        var dggdate = dggui.dggdate;
        var droptree = dggui.droptree;

        mortgageLoan();

        // console.log($(".active").attr("data-target"));
        $(".tab-switch").click(function () {
            var target = $(this).attr("data-target");
            $(".tab-switch").each(function () {
                if (target == $(this).attr("data-target")) {
                    $(this).addClass("active");
                } else {
                    $(this).removeClass("active");
                }
            });
            switch ($(".active").attr("data-target")) {
                case "1":
                    dggui.dialog.loading();
                    mortgageLoan();
                    break;
                case "2":
                    dggui.dialog.loading();
                    creditLoan();
                    break;
                case "3":
                    dggui.dialog.loading();
                    capitalBusiness();
                    break;
                default:
                    dggui.dialog.loading();
                    mortgageLoan();
                    break;
            }
        })

        //抵押贷款
        function mortgageLoan(){
            $.ajax({
                url:completeOrder.mortgage_loan,
                dataType: 'html',
                success:function(html){
                    dggui.dialog.loading('close');
                    $("#screeningArea").html(html);
                    //初始化部门下拉框
                    queryAllDep("#flowUserDep");
                    //初始化抵押贷款产品
                    initProductCode("#productCode","BUS_YT_DK_DYDK");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#productCode'),
                        width: "160px"
                    });
                    //渠道初始化
                    $('#productCode').on('change', function (e) {
                        var produtId = $("#productCode").val();
                        initChannel("#channelCode",produtId);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#channelCode'),
                            width: "160px"
                        });
                    });
                    //初始化流程人员
                    initUser("RZSC_FLOW_USER","role","#flowUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#flowUserId'),
                        width: "160px"
                    });

                    var opt={
                        "elem":"#mortgageLoan",
                        "switchStatus":"#mortgageLoan",
                        "ajax": completeOrder.list,
                        "scrollX": "true",//是否开启横项滚动
                        "fnServerParams": function (aoData) {
                            aoData = $.extend(aoData, {
                                productOrgId:$("#productOrgId").val(),
                                productId:$("#productCode").val(),
                                channelId:$("#channelCode").val(),
                                searchKey:$("#searchKey").val(),
                                businessName : $('#businessName').val(),
                                flowUserId:$("#flowUserId").val(),
                                flowUserDep: $("#flowUserDep").attr("data-id"),
                                businessProductCode:$("#businessProductCode").val(),
                            });
                            return aoData;
                        },
                        "aoColumns": [
                            {
                                "title": "序号",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return meta.row + 1;
                                }
                            },
                            {
                                "title": "生产事业部",
                                "data": "productOrgName",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm = '<div class="order-render"><b>'+data ? data : ''+'<b></div>';
                                    return htm;
                                }
                            },
                            {
                                "title": "部门",
                                "data": "flowUserOrgName",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "姓名",
                                "data": "flowUserName",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"业务类型",
                                "orderable": false,
                                "data": "businessProductName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"产品名称",
                                "orderable": false,
                                "data": "productName",
                                "render": function (data, type, full, meta) {
                                    var  productCode = $("#productCode").val();
                                    return productCode ? data : '全部';
                                }
                            },
                            {
                                "title":"渠道名称",
                                "orderable": false,
                                "data": "channelName",
                                "render": function (data, type, full, meta) {
                                    var  channelCode = $("#channelCode").val();
                                    return channelCode ? data : '全部';
                                }
                            },
                            {
                                "title":"办理中",
                                "data": "handling",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            /*         {
                                         'title': '暂缓中',
                                         'data': "reprieve",
                                         "orderable": false,
                                         "render": function(data, type, row, meta) {
                                             return data ? data : 0;
                                         }
                                     },*/
                            {
                                "title":"订单已超期",
                                "data": "overdue",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"匹配渠道",
                                "data": "channel",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"预签申请合同",
                                "data": "preContract",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"已报审",
                                "data": "totalReporting",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"审核通过",
                                "data": "auditApproval",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"通过金额（元）",
                                "orderable": false,
                                "data": "throughAmount",
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"结案注销",
                                "data": "writeOffAmount",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                'title': '已办抵押',
                                'data': "mortgageAmount",
                                "orderable": false,
                                "render": function (data, type, row, meta) {
                                    return data ? data : 0;
                                }
                            }
                        ],
                        "fnInitComplete": function (oSettings) {
                            var json =jQuery.parseJSON(oSettings.jqXHR.responseText);
                            // console.log(JSON.stringify(json))
                            handleResult(json);
                        }
                    };
                    tables = table.render(opt);
                    $('.searchBtn').click(function (){
                        // tables.ajax.reload();
                        // 这里由于自定义显示/隐藏列功能占用fnDrawCallback方法，
                        // 所以上方调用fnInitComplete（初始化结束后的回调函数）方法初始化时渲染额外参数
                        // 该方法每次都需要将表格摧毁后才能进行。
                        tables.destroy();
                        tables = table.render(opt);
                    });
                    // 处理dataTable 异常错误信息
                    $.fn.dataTable.ext.errMode = 'none';//不抛出异常
                    tables.on( 'error.dt', function ( e, settings, techNote, message ) {
                        //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
                        if(checkEmpty(settings.jqXHR.responseJSON.error)){                 dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);             }
                    });
                }
            });
        }
        //信用贷款
        function creditLoan(){
            $.ajax({
                url:completeOrder.credit_loan,
                dataType: 'html',
                success:function(html){
                    dggui.dialog.loading('close');
                    $("#screeningArea").html(html);
                    //初始化所属生产事业部
                    //初始化部门下拉框
                    queryAllDep("#flowUserDep");
                    //初始化抵押贷款产品
                    initProductCode("#productCode","BUS_YT_DK_XYDK");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#productCode'),
                        width: "160px"
                    });
                    //渠道初始化
                    $('#productCode').on('change', function (e) {
                        var produtId = $("#productCode").val();
                        initChannel("#channelCode",produtId);
                        select2.render({
                            placeholder: "请选择",
                            allowClear: true,
                            elem: $('#channelCode'),
                            width: "160px"
                        });
                    });
                    //初始化流程人员
                    initUser("RZSC_FLOW_USER","role","#flowUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#flowUserId'),
                        width: "160px"
                    });

                    var opt={
                        "elem":"#creditLoan",
                        "ajax": completeOrder.list,
                        "scrollX": "true",//是否开启横项滚动
                        "oneSelectCheck":true,//单选，同时选中复选框
                        "switchStatus": "#creditLoan",
                        "fnServerParams": function (aoData) {
                            //搜索条件
                            aoData = $.extend(aoData, {
                                productOrgId:$("#productOrgId").val(),
                                productId:$("#productCode").val(),
                                channelId:$("#channelCode").val(),
                                flowUserId:$("#flowUserId").val(),
                                businessName : $('#businessName').val(),
                                businessProductCode : $('#businessProductCode').val(),
                                flowUserDep: $("#flowUserDep").attr("data-id"),
                                signOrgOrBusId:$("#signOrg").attr("data-id")
                            });
                            return aoData;
                        },
                        "aoColumns": [
                            {
                                "title": "序号",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return meta.row + 1;
                                }
                            },
                            {
                                "title": "生产事业部",
                                "data": "productOrgName",
                                "orderable": false,
                                "render": function(data, type, row, meta) {
                                    var htm = '<div class="order-render"><b>'+data ? data : ''+'<b></div>';
                                    return htm;
                                }
                            },
                            {
                                "title": "部门",
                                "data": "flowUserOrgName",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "姓名",
                                "data": "flowUserName",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"业务类型",
                                "orderable": false,
                                "data": "businessProductName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"产品名称",
                                "orderable": false,
                                "data": "productName",
                                "render": function (data, type, full, meta) {
                                    var  productCode = $("#productCode").val();
                                    return productCode ? data : '全部';
                                }
                            },
                            {
                                "title":"渠道名称",
                                "orderable": false,
                                "data": "channelName",
                                "render": function (data, type, full, meta) {
                                    var  channelCode = $("#channelCode").val();
                                    return channelCode ? data : '全部';
                                }
                            },
                            {
                                "title":"办理中",
                                "data": "handling",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            /*         {
                                         'title': '暂缓中',
                                         'data': "reprieve",
                                         "orderable": false,
                                         "render": function(data, type, row, meta) {
                                             return data ? data : 0;
                                         }
                                     },*/
                            {
                                "title":"订单超期",
                                "data": "overdue",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"匹配渠道",
                                "data": "channel",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"完善资料",
                                "orderable": false,
                                "data": "completeMaterial",
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"报审",
                                "data": "totalReporting",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"审核通过",
                                "data": "auditApproval",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },
                            {
                                "title":"通过金额（元）",
                                "orderable": false,
                                "data": "throughAmount",
                                "render": function (data, type, full, meta) {
                                    return data ? data : 0;
                                }
                            },


                        ],
                        "fnInitComplete": function (oSettings) {
                            var json =jQuery.parseJSON(oSettings.jqXHR.responseText);
                            handleResult(json);
                        }
                    };
                    tables = table.render(opt);
                    $('.searchBtn').click(function (){
                        // tables.ajax.reload();
                        // 这里由于自定义显示/隐藏列功能占用fnDrawCallback方法，
                        // 所以上方调用fnInitComplete（初始化结束后的回调函数）方法初始化时渲染额外参数
                        // 该方法每次都需要将表格摧毁后才能进行。
                        tables.destroy();
                        tables = table.render(opt);
                    });
                    // 处理dataTable 异常错误信息
                    $.fn.dataTable.ext.errMode = 'none';//不抛出异常
                    tables.on( 'error.dt', function ( e, settings, techNote, message ) {
                        //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
                        if(checkEmpty(settings.jqXHR.responseJSON.error)){                 dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);             }
                    });
                }
            });
        }
        //资金业务
        function capitalBusiness(){
            $.ajax({
                url:completeOrder.capital_business,
                dataType: 'html',
                success:function(html){
                    dggui.dialog.loading('close');
                    $("#screeningArea").html(html);
                    //初始化部门下拉框
                    queryAllDep("#flowUserDep");

                    //初始化流程人员
                    initUser("RZSC_FLOW_USER","role","#flowUserId");
                    select2.render({
                        placeholder: "请选择",
                        allowClear: true,
                        elem: $('#flowUserId'),
                        width: "160px"
                    });

                    var opt={
                        "elem":"#capitalBusiness",
                        "ajax": completeOrder.list,
                        "scrollX": "true",//是否开启横项滚动
                        "oneSelectCheck":true,//单选，同时选中复选框
                        "switchStatus": "#capitalBusiness",
                        "fnServerParams": function (aoData) {
                            aoData = $.extend(aoData, {
                                productOrgId:$("#productOrgId").val(),
                                productId:$("#productCode").val(),
                                channelId:$("#channelCode").val(),
                                flowUserId:$("#flowUserId").val(),
                                businessName : $('#businessName').val(),
                                businessProductCode : $('#businessProductCode').val(),
                                flowUserDep: $("#flowUserDep").attr("data-id"),
                                signOrgOrBusId:$("#signOrg").attr("data-id")
                            });
                            return aoData;
                        },
                        "aoColumns": [
                            {
                                "title": "序号",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return meta.row + 1;
                                }
                            },
                            {
                                "title": "生产事业部",
                                "data": "productOrgName",
                                "orderable": false,
                                "render": function(data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "部门",
                                "data": "flowUserOrgName",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title": "姓名",
                                "data": "flowUserName",
                                "orderable": false,
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"业务类型",
                                "orderable": false,
                                "data": "businessProductName",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            {
                                "title":"办理中",
                                "orderable": false,
                                "data": "handling",
                                "render": function (data, type, full, meta) {
                                    return data ? data : '';
                                }
                            },
                            /*        {
                                        'title': '已暂缓',
                                        'data': "reprieve",
                                        "orderable": false,
                                        "render": function(data, type, row, meta) {
                                            return data ? data : 0;
                                        }
                                    }*/
                        ],
                        "fnInitComplete": function (oSettings) {
                            var json =jQuery.parseJSON(oSettings.jqXHR.responseText);
                            handleResult(json);
                        }
                    };
                    tables = table.render(opt);
                    $('.searchBtn').click(function (){
                        // tables.ajax.reload();
                        // 这里由于自定义显示/隐藏列功能占用fnDrawCallback方法，
                        // 所以上方调用fnInitComplete（初始化结束后的回调函数）方法初始化时渲染额外参数
                        // 该方法每次都需要将表格摧毁后才能进行。
                        tables.destroy();
                        tables = table.render(opt);
                    });
                    $.fn.dataTable.ext.errMode = 'none';//不抛出异常
                    tables.on( 'error.dt', function ( e, settings, techNote, message ) {
                        //dggui.dialog.errors("表格查询错误，请联系管理员", 2000);
                        if(checkEmpty(settings.jqXHR.responseJSON.error)){                 dggui.dialog.errors(settings.jqXHR.responseJSON.error, 2000);             }
                    });
                }
            });
        }

    });
    //导出
    function excelExportMortgageLoan(url) {
        var obj = new Object();
        obj.productOrgId = $("#productOrgId").val();
        obj.productId = $("#productCode").val();
        obj.channelId = $("#channelCode").val();
        obj.flowUserId = $("#flowUserId").val();
        obj.businessName = $("#businessName").val();
        obj.businessProductCode = $("#businessProductCode").val();
        obj.flowUserDep = $("#flowUserDep").attr("data-id");
        formSubmit(url, obj);
    }

</script>
</body>
</html>